Computer Science Programming Basics with Ruby
Author: Ophir Frieder, Gideon Frieder & David Grossman , Date: March 26, 2014
, Views: 735
Example: Find the Max—Hash
Example 6-10. Find the max—hash
1 scores = Hash.new 2 3 scores["Geraldo"] = [98, 95, 93, 96] 4 scores["Brittany"] = [74, 90, 84, 92] 5 scores["Michael"] = [72, 87, 68, 54, 10] 6 7 maxscore = 0 8 for name in scores.keys 9 column = 0 10 while (column < scores[name].size) 11 12 if (scores[name][column] > maxscore) 13 maxname = name 14 maxscore = scores[name][column] 15 end 16 column = column + 1 17 end 18 end 19 20 puts maxname + " has the highest score." 21 puts "The highest score is: " + maxscore.to_s
Copyright Disclaimer:
This site does not store any files on its server. We only index and link
to content provided by other sites. Please contact the content providers
to delete copyright contents if any and email us, we'll remove relevant
links or contents immediately.